# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=blosc
_srcname=c-blosc
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.18.1
pkgrel=1
pkgdesc="A blocking, shuffling and loss-less compression library (mingw-w64)"
arch=('any')
url='http://blosc.org/'
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-snappy"
         "${MINGW_PACKAGE_PREFIX}-zstd"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-lz4")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/Blosc/c-blosc/archive/v${pkgver}.tar.gz")
sha256sums=('18730e3d1139aadf4002759ef83c8327509a9fca140661deb1d050aebba35afb')

prepare() {
  cd "${srcdir}/${_srcname}-${pkgver}"
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_BUILD_TYPE="Release" \
      -DBUILD_SHARED_LIBS="ON" \
      -DPREFER_EXTERNAL_LZ4="ON" \
      -DPREFER_EXTERNAL_ZLIB="ON" \
      -DPREFER_EXTERNAL_SNAPPY="ON" \
      -DPREFER_EXTERNAL_ZSTD="ON" \
      -DBUILD_TESTS="OFF" \
      ../${_srcname}-${pkgver}

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  # License
  install -Dm644 ${srcdir}/${_srcname}-${pkgver}/LICENSES/BLOSC.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
